package com.org.netty.rpc.provider;

import com.org.netty.rpc.entity.School;
import com.org.netty.rpc.entity.Student;
import com.org.netty.rpc.publicInterface.RpcService;
import com.org.netty.rpc.utils.ProtostuffUtils;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author: Lixy
 * @email: 1908598362@qq.com
 * @date: 2022/2/11 星期五 19:26
 */
public class RpcServiceImpl implements RpcService {

    @Override
    public String SendHello(String msg) {
        System.out.println("接收到客户端发送的消息:"+msg);
        if (msg!=null){
            return "Hello,客户端,消息已收到  [" +msg+" ]";
        }else {
            return "Hello,客户端,消息已收到";
        }
    }

    @Override
    public School chooseShl() {
        Student stu1 = new Student("张三",20);
        Student stu2 = new Student("李四",21);
        List<Student> students = new ArrayList<Student>();
        students.add(stu1);
        students.add(stu2);
        School school = new School("西工大",students);
        //首先是序列化
        byte[] bytes = ProtostuffUtils.serialize(school);
        System.out.println("序列化后: " + bytes.length);
        //然后是反序列化
        School group1 = ProtostuffUtils.deserialize(bytes,School.class);
        System.out.println("反序列化后: " + school.toString());
        return group1;
    }


}
